<template>
  <div class="emigrated">
    <div class="table-data" :class="{ gray: type === 'everyday' }">
      <div v-if="type === 'everyday'" v-loading="listLoading" class="course-list">
        <el-radio-group v-model="radioItem" @change="handleChange">
          <el-row>
            <el-col v-for="(item, index) in tableData" :key="item.id" :span="5">
              <el-radio :label="item">
                <div class="course-list-item">
                  <div class="item-img c">
                    <img :src="filterRushImg(item.dailyImg, index)" alt class="bg" />
                    <img v-if="view + item.dailyImg" :src="view + item.dailyImg" class="item-bg-img" :onerror="defaultRushImg" />
                    <div class="title etc">{{ item.dailyName || '' }}</div>
                    <div v-if="item.status == 'BDZT02'" class="pub">
                      <span>禁用</span>
                    </div>
                  </div>
                  <p class="item-mark etc">试题数量：{{ item.questionNumber || '' }}</p>
                  <p class="item-mark etc">题库：{{ item.questionIdValue || '未设置' }}</p>
                </div>
              </el-radio>
            </el-col>
            <div v-if="tableData.length <= 0" class="nodata">
              <img src="../images/nodata.png" />
            </div>
          </el-row>
        </el-radio-group>
      </div>
      <v-table
        v-if="type === 'special'"
        :list="tableData"
        :tag="tag"
        :source-arr="['activityImg', 'imgIdUrl']"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :cell-style="() => {}"
        @handleSelectionChange="select"
      />
    </div>
    <div class="page">
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import { queryEmigratedPage } from '../api'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import defaultRushImg from './../images/rush-default.png'
import rushFive from '@/views/skill/rush/images/rush-five.png'
import rushSix from '@/views/skill/rush/images/rush-six.png'
import rushSeven from '@/views/skill/rush/images/rush-seven.png'
import rushEight from '@/views/skill/rush/images/rush-eight.png'
import rushOne from '@/views/skill/rush/images/rush-one.png'
import rushTwo from '@/views/skill/rush/images/rush-two.png'
import rushThree from '@/views/skill/rush/images/rush-three.png'
import rushFour from '@/views/skill/rush/images/rush-four.png'
export default {
  name: 'Emigrated',
  components: { Pagination, VTable },
  props: {
    type: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      defaultRushImg: 'this.src="' + defaultRushImg + '"',
      radioItem: '',
      view: '/API-DOCUMENT/document/file/download?id=',
      listLoading: false,
      total: 0,
      tableData: [],
      listQuery: {
        page: 1,
        limit: 10
      },
      tag: 'newSpecial'
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleChange() {
      this.$emit('radio', this.radioItem)
    },
    /**
     * 格式化闯关背景图片
     * @param index
     * @returns {*}
     */
    filterRushImg(imgId, index) {
      if (imgId) {
        if (index % 4 === 0) {
          return rushFive
        }
        if (index % 4 === 1) {
          return rushSix
        }
        if (index % 4 === 2) {
          return rushSeven
        }
        if (index % 4 === 3) {
          return rushEight
        }
      } else {
        if (index % 4 === 0) {
          return rushOne
        }
        if (index % 4 === 1) {
          return rushTwo
        }
        if (index % 4 === 2) {
          return rushThree
        }
        if (index % 4 === 3) {
          return rushFour
        }
      }
    },
    select(arr) {
      this.$emit('select', arr)
    },
    getList() {
      this.listLoading = true
      var query = {
        page: this.listQuery.page,
        pageSize: this.listQuery.limit,
        status: 'ZT01'
      }
      if (this.type === 'everyday') {
        query.status = 'BDZT01'
      }
      return new Promise((resolve, reject) => {
        queryEmigratedPage(this.type, query)
          .then((response) => {
            this.tableData = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    },
    filtercolumn(scope, item) {
      if (item === 'questionIdValue') {
        return scope.row[item] ? scope.row[item] : '未设置'
      } else if (item === 'activityBackgroundColor') {
        return `<span style="display: inline-block;width: 40px; height: 40px;background-color: ${scope.row[item] || '无'}"></span>`
      } else if (item === 'activityImg') {
        return this.view + scope.row[item]
      } else {
        return scope.row[item]
      }
    }
  }
}
</script>

<style type="text/css" lang="scss">
.emigrated {
  height: 550px;
  display: flex;
  overflow: hidden;
  flex-direction: column;
  .el-radio-group {
    display: block !important;
    .el-radio {
      width: 100%;
    }
  }
  .table-data {
    flex: 1;
    overflow-y: auto;
    &.gray {
      padding: 0 20px;
      background: rgb(247, 247, 248);
    }
    .course-list {
      min-height: 300px;
      margin-top: 20px;
      .el-row {
        .el-col-5 {
          width: 20%;
        }
      }
      .course-list-item {
        background-color: #ffffff;
        padding: 10px 10px 5px;
        margin-right: 10px;
        margin-bottom: 10px;
        box-shadow: 0 5px 10px rgba(254, 90, 97, 0.05);
        position: relative;

        .item-img {
          width: 100%;
          height: 150px;
          overflow: hidden;
          position: relative;
          .title {
            width: 60%;
            font-size: 12px;
            color: #fff;
            position: absolute;
            top: 10px;
            left: 10px;
          }
          .bg {
            position: absolute;
            width: 100%;
            height: 100%;
            z-index: 0;
            transition: all 0.2s linear;
            &:hover {
              transform: scale(1.1, 1.1);
              filter: contrast(130%);
            }
          }
          .item-bg-img {
            position: absolute;
            right: 10px;
            bottom: 10px;
            width: 60px;
            height: 60px;
            border-radius: 50%;
          }
          &.o {
            height: 130px;
          }
          .pub {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 1);
            opacity: 0.5;
            z-index: 1;
            span {
              font-size: 12px;
              color: #ffffff;
              position: absolute;
              top: 50%;
              left: 50%;
              transform: translate(-50%, -50%);
            }
          }
        }
        .item-mark {
          font-size: 12px;
          margin: 5px 0;
          line-height: 1.5;
          font-family: PingFangSC-Regular;
          font-weight: 400;
          color: rgba(166, 166, 166, 1);
        }
        .item-type {
          height: 20px;
          line-height: 20px;
          .type-gate {
            margin-right: 5px;
            img {
              width: 40px;
            }
          }
          .type-exam {
            img {
              width: 40px;
            }
          }
          .type-num {
            color: #333333;
            font-weight: 400;
            font-size: 12px;
            float: right;
          }
        }
        .item-btns {
          display: flex;
          margin-top: 10px;
          position: relative;
          .el-button {
            flex: 1;
            span {
              font-size: 14px;
              font-weight: 500;
            }
          }
          &:before {
            content: '';
            position: absolute;
            top: 0;
            left: -10px;
            right: -10px;
            height: 1px;
            background-color: #e2e3e8;
          }
        }
      }
    }
  }

  .page {
    height: 50px;
  }
}
</style>
